import open3d as o3d
import open3d.core as o3c
import torch

# 检查 Open3D 是否能访问 CUDA
print("--- Open3D CUDA Check ---")
try:
    cuda_device = o3c.Device("CUDA:0")
    if cuda_device.is_cuda():
        print(f"Open3D can access CUDA. Device: {cuda_device.get_type_name()}:{cuda_device.get_id()}")
        # 尝试创建一个简单的张量在 CUDA 上
        try:
            a = o3c.Tensor([1,2,3], device=cuda_device)
            print("Successfully created Open3D tensor on CUDA.")
        except Exception as e:
            print(f"Failed to create Open3D tensor on CUDA: {e}")
    else:
        print("Open3D CUDA device check returned false (not CUDA or not available).")
except Exception as e:
    print(f"Error checking/using Open3D CUDA: {e}")
    print("This might indicate a CPU-only Open3D or CUDA driver/toolkit issues.")

# 检查 PyTorch 是否能访问 CUDA
print("\n--- PyTorch CUDA Check ---")
if torch.cuda.is_available():
    print(f"PyTorch can access CUDA. CUDA version: {torch.version.cuda}")
    print(f"Number of GPUs available: {torch.cuda.device_count()}")
    print(f"Current CUDA device: {torch.cuda.current_device()}")
    print(f"Device name: {torch.cuda.get_device_name(torch.cuda.current_device())}")
    # 尝试创建一个简单的张量在 CUDA 上
    try:
        a = torch.tensor([1., 2.], device='cuda')
        print("Successfully created PyTorch tensor on CUDA.")
    except Exception as e:
        print(f"Failed to create PyTorch tensor on CUDA: {e}")
else:
    print("PyTorch cannot access CUDA.")

print(f"\nOpen3D version: {o3d.__version__}")
